package com.ruoyi.web.controller.djb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.djb.domain.DjbReason;
import com.ruoyi.djb.service.IDjbReasonService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 事由管理Controller
 * 
 * @author xxd
 * @date 2024-07-15
 */
@Controller
@RequestMapping("/djb/districtReason")
public class DjbReasonController extends BaseController
{
    private String prefix = "djb/districtReason";

    @Autowired
    private IDjbReasonService djbReasonService;

    @RequiresPermissions("djb:districtReason:view")
    @GetMapping()
    public String districtReason()
    {
        return prefix + "/districtReason";
    }

    /**
     * 查询事由管理列表
     */
    @RequiresPermissions("djb:districtReason:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbReason djbReason)
    {
        startPage();
        List<DjbReason> list = djbReasonService.selectDjbReasonList(djbReason);
        return getDataTable(list);
    }

    /**
     * 导出事由管理列表
     */
    @RequiresPermissions("djb:districtReason:export")
    @Log(title = "事由管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbReason djbReason)
    {
        List<DjbReason> list = djbReasonService.selectDjbReasonList(djbReason);
        ExcelUtil<DjbReason> util = new ExcelUtil<DjbReason>(DjbReason.class);
        return util.exportExcel(list, "事由管理数据");
    }

    /**
     * 新增事由管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存事由管理
     */
    @RequiresPermissions("djb:districtReason:add")
    @Log(title = "事由管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbReason djbReason)
    {
        return toAjax(djbReasonService.insertDjbReason(djbReason));
    }

    /**
     * 修改事由管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbReason djbReason = djbReasonService.selectDjbReasonById(id);
        mmap.put("djbReason", djbReason);
        return prefix + "/edit";
    }

    /**
     * 修改保存事由管理
     */
    @RequiresPermissions("djb:districtReason:edit")
    @Log(title = "事由管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbReason djbReason)
    {
        return toAjax(djbReasonService.updateDjbReason(djbReason));
    }

    /**
     * 删除事由管理
     */
    @RequiresPermissions("djb:districtReason:remove")
    @Log(title = "事由管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbReasonService.deleteDjbReasonByIds(ids));
    }
}
